/* 封装请求接口 */
const BASE_URL = 'https://tea.qingnian8.com/api/bizhi';
export function request(obj = {}) {
	let {
		url,
		data,
		method = "GET",
		header = {}
	} = obj;

	url = BASE_URL + url;
	header["access-key"] = "@20020511";

	return new Promise((resolve, reject) => {
		uni.request({
			url,
			method,
			header,
			data,
			success(res) {
				if (res.data.errCode === 0) {
					resolve(res.data);
				} else if (res.data.errCode === 400) {
					uni.showModal({
						title: "错误提示",
						content: res.data.errMsg,
						showCancel: false
					})
				} else {
					uni.showToast({
						title: res.data.errMsg,
						icon: "none"
					})
				}
			},
			fail() {
				uni.showToast({
					title: "请求出错",
					icon: "none"
				})
			}
		})

	})
}